package com.emr.web.controller.emr;


import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.emr.common.annotation.Log;
import com.emr.common.base.AjaxResult;
import com.emr.common.enums.BusinessType;
import com.emr.framework.web.page.TableDataInfo;
import com.emr.module.domain.Operation;
import com.emr.module.service.IOperationService;
import com.emr.module.service.IPersonalService;
import com.emr.system.service.ISysUserService;
import com.emr.web.core.base.BaseController;

/**
 * 手术记录 信息操作处理
 * 
 * @author emr
 * @date 2019-02-20
 */
@Controller
@RequestMapping("/module/operation")
public class OperationController extends BaseController
{
    private String prefix = "module/operation";
	
	@Autowired
    private ISysUserService userService;
	@Autowired
	private IPersonalService ipersonalService ;

    
	@Autowired
	private IOperationService operationService;
	
	@RequiresPermissions("module:operation:view")
	@GetMapping()
	public String operation()
	{
	    return prefix + "/operation";
	}
	
	/**
	 * 查询手术记录列表
	 */
	@RequiresPermissions("module:operation:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Operation operation)
	{
		startPage();
		if("".equals(operation.getBingrName())){
			operation.setBingrName(null);
		}
        List<Operation> list = operationService.selectOperationList(operation);
		return getDataTable(list);
	}
	
	/**
	 * 新增手术记录
	 */
	@GetMapping("/add")
	public String add(ModelMap mmap)
	{	
		mmap.put("posts",ipersonalService.selectIcdAll());
		mmap.put("hushi", userService.selectUserAll());
		mmap.put("yisheng", userService.selectyishengAll());
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存手术记录
	 */
	@RequiresPermissions("module:operation:add")
	@Log(title = "手术记录", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Operation operation)
	{			
		return toAjax(operationService.insertOperation(operation));
	}

	/**
	 * 修改手术记录
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		
		Operation operation = operationService.selectOperationById(id);
		mmap.put("posts", ipersonalService.selectUPersonalByIds(operation.getPersonalId()));
		mmap.put("hushi", userService.selecthushiAlls(operation.getPersonalHushiid()));
		mmap.put("yisheng", userService.selectyishengAlls(operation.getPersonalYishengid()));
		
		/*mmap.put("hushi", userService.selectUserById(operation.getPersonalHushiid().longValue()));
		mmap.put("yisheng", userService.selectUserById(operation.getPersonalHushiid().longValue()));*/
		
		
		mmap.put("operation", operation);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存手术记录
	 */
	@RequiresPermissions("module:operation:edit")
	@Log(title = "手术记录", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Operation operation)
	{		
		return toAjax(operationService.updateOperation(operation));
	}
	
	/**
	 * 删除手术记录
	 */
	@RequiresPermissions("module:operation:remove")
	@Log(title = "手术记录", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(operationService.deleteOperationByIds(ids));
	}
	
}
